package main

import (
	"fmt"
	mysqlCfg "github.com/go-sql-driver/mysql"
	"github.com/redis/go-redis/v9"
	"huijing_mall/server"
	"math/rand"
	"time"

	"huijing_mall/pkg/logger"
	"huijing_mall/pkg/vipercfg"
	"huijing_mall/router"
)

var Version = "0.0.11"

//	@title			灰鲸商城系统API文档
//	@version		0.01
//	@description	灰鲸商城系统API文档

//	@host		localhost:9091
//	@BasePath	/

// @securityDefinitions.apikey	Token
// @in							header
// @name						Token
func main() {
	rand.Seed(time.Now().UnixNano())
	logger.LogInit(logger.NewLogConfig())
	cfg := vipercfg.ViperInit("") //默认dev

	logger.Info(fmt.Sprintf("Version：%v", Version))
	// 程序的正常逻辑
	logger.Info("Working...")
	server.Run(cfg.ServerPort,
		&mysqlCfg.Config{
			User:   cfg.Database.Name,
			Passwd: cfg.Database.Pwd,
			Addr:   fmt.Sprintf("%s:%d", cfg.Database.Host, cfg.Database.Port),
			DBName: cfg.Database.Database,
			Params: map[string]string{
				"charset": cfg.Database.Charset,
			},
			Loc:                  time.Local,
			AllowNativePasswords: true, //allowNativePasswords=true（避免认证失败）
		},
		&redis.Options{
			Addr:     fmt.Sprintf("%s:%d", cfg.CacheBase.Host, cfg.CacheBase.Port),
			Password: cfg.CacheBase.Pwd, // No Password Set
			DB:       0,
		},
		nil,
		//mq.NewRabbitMQ(cfg.RabbitMQ),
		router.Router,
	)

}
